/**
 * Created by zander on 2017/11/28.
 */


function updataPwd() {
    var localStorage = window.localStorage;
    var name = localStorage.getItem('name');
    var oldPwd = document.getElementById('inputoldPwd').value;
    var newPwd = document.getElementById('inputnewPwd').value;
    var newPwd1 = document.getElementById('inputnewPwd1').value;
    if (newPwd == newPwd1) {
        bootbox.confirm({
            size: "small",
            message: "是否确认更新密码？",
            callback: function (result) {
                if (result == true) {
                    $.ajax({
                        type: "POST",
                        url: "/updata",
                        data: {username: name, oldPwd: oldPwd, newPwd: newPwd},
                        dataType: "json",
                        success: function (ret) {
                            if (ret.status == "0000") {
                                alert("密码更新成功！")
                                top.location.href = "/logout"
                            } else if (ret.status == "0001") {
                                alert("操作失败,请稍后重试！")
                            } else if (ret.status == "0002") {
                                alert("未查询到用户名,请重新登录")
                            }
                        },
                        error: function () {
                            alert("Error 500,请联系开发人员！");
                        }
                    });
                }
            }
        })
    } else {
        alert("两次输入的密码不一致！");
    }
}
